package pl.kosmowska.ewelina.client.views.widgets.popup;


import com.google.gwt.user.client.ui.DialogBox;


public abstract class AbstractPopupPanel extends DialogBox {

    public abstract boolean initDialogBox();


    protected boolean secondLayer;

    public void closeWindow() {
        hide();
        if (!isSecondLayer()) {
            hideBackground();
        }
    }

    protected void initAll() {
        initBackground();
        if (initDialogBox()) {
            center();
            show();
            hoverPopupButton();
        }
    }

    public void reShow() {
        initBackground();
        this.center();
        this.show();
    }

    public boolean isSecondLayer() {
        return secondLayer;
    }

    public void setSecondLayer(boolean secondLayer) {
        this.secondLayer = secondLayer;
    }

    public static native void initBackground() /*-{
        $wnd.$(document).ready(function () {
            $wnd.$(".myPopupBackground").css({
                "opacity":"0.2"
            });
            $wnd.$(".myPopupBackground").fadeIn("slow");
        });
    }-*/;

    public static native void hideBackground() /*-{
        $wnd.$(document).ready(function () {
            $wnd.$(".myPopupBackground").fadeOut("slow");
        });
    }-*/;

    public static native void hoverPopupButton() /*-{
        $wnd.$('.hoverClass').hover(
                function () {
                    $wnd.$(this).addClass('ui-state-hover');
                },
                function () {
                    $wnd.$(this).removeClass('ui-state-hover');
                });
    }-*/;
}